<!--
    @name 服务活动查询-服务活动详情
    @author hezm
-->
<template>
  <section>
    <el-dialog
      v-dialogDrag
      :title="textMap[popupsState]"
      :visible="popupsVisible"
      width="70%"
      :append-to-body="true"
      :close-on-click-modal="false"
      @close="close"
      @opened="openDialog"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />
      <div class="filter-container filter-title">活动信息</div>
      <!-- 顶部按钮 -->
      <div class="filter-container filter-params">
        <el-row id="elrow" ref="vailComponentList" :gutter="24">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter((o) => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :span="comp.span || 6"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :o-fields="comp.oFields"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div class="eltabs">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="附件" name="first">
            <attachment :data-for-form="dataForForm" />
          </el-tab-pane>

          <el-tab-pane label="车型清单" name="second">
            <carTypeList :data-for-form="dataForForm" />
          </el-tab-pane>

          <el-tab-pane label="客户清单" name="third">
            <customerList :data-for-form="dataForForm" />
          </el-tab-pane>

          <el-tab-pane label="备件" name="fourth">
            <accessories :data-for-form="dataForForm" />
          </el-tab-pane>

          <el-tab-pane label="工时清单" name="fifth">
            <laborHour :data-for-form="dataForForm" />
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import OneTableTemplate from '@/components/templates/oneTable'
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import { formMixins } from '@/components/mixins/formMixins'
import api from '@/api/se/serviceActivities'

export default {
  name: 'ServiceRelesedetil',
  components: {
    OneTableTemplate,
    dialogHeader: () => import('@/components/dialogHeader'),
    attachment: () => import('./attachment.vue'),
    carTypeList: () => import('./carTypeList.vue'),
    customerList: () => import('./customerList.vue'),
    accessories: () => import('./accessories.vue'),
    laborHour: () => import('./laborHour.vue')

  },

  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins, formMixins],

  props: {
    popupsVisible: { type: Boolean, default: false },
    dynamicEditRowData: { type: Object, default: function() { return {} } }
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      activeName: 'first',
      dataForForm: {},
      apiConfig: {},
      textMap: {
        edit: '服务活动详情'
      },

      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '活动编号：',
              codeField: 'actionCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey2',
              labelName: '活动类型：',
              codeField: 'actionTypeCode',
              lookuptype: 'SE1006',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              disabled: true,
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey3',
              labelName: '发布人：',
              codeField: 'publisher',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey4',
              labelName: '开始时间：',
              codeField: 'beginDate',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey5',
              labelName: '结束时间：',
              codeField: 'endDate',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey6',
              labelName: '发布时间：',
              codeField: 'publishDate',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey7',
              labelName: '活动主题：',
              codeField: 'actionName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey9',
              labelName: '客户活动详情:',
              codeField: 'actionCustDesc',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMust: true,
              span: 16
            }
          ],

      formField: this.$utils.getFormField(this, {
        actionCode: '',
        actionName: '',
        beginDate: '',
        endDate: '',
        actionStateCode: '',
        actionTypeCode: '',
        publisher: '',
        publishDate: '',
        actionCustDesc: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  methods: {
    openDialog() {
      this.dataForForm = this.dynamicEditRowData
    },
    accessories() {
      const queryObj = {
        // 保存mutation
        type: 'query',
        // api配置
        apiConfig: api.queryParts,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          actionCode: this.dynamicEditRowData.actionCode,
          actionId: this.dynamicEditRowData.actionId
        }
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then(response => {
        if (response.result === '1') {
          this.$message({
            message: response.msg,
            type: 'success',
            duration: 1000
          })
        } else {
          this.$message({
            message: response.msg,
            type: 'warn',
            duration: 1000
          })
        }
      })
    },

    close(type) {
      this.$emit('close', type)
    },

    handleClick(tab, event) {
      // console.log(tab, event)
    }
  }
}
</script>

<style lang="scss" scoped>

/deep/.filter-params .el-col {
  margin-bottom: 15px;
}

#elrow {
  margin-right: 0 !important;

}
</style>
